/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.client.db.tasks;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import pl.cezary.butler.walili.client.DownloadTaskStatus;
import pl.cezary.butler.walili.server.db.tasks.UpdateTask;

/**
 *
 * @author Czarek
 */
public class InitClientTasks extends UpdateTask {
    
    private static final Logger log = Logger.getLogger(InitClientTasks.class.getName());

    @Override
    public void execute() throws SQLException {
        final int count = getJdbcTemplate().queryForInt("select count(id) from filesToDownload");
        final int updated =  getJdbcTemplate().update("update filesToDownload set status = ? where status in(?,?)",DownloadTaskStatus.NEW.ordinal(), DownloadTaskStatus.IN_PROGRES.ordinal(), DownloadTaskStatus.QUEUED.ordinal());
        log.log(Level.INFO,"{0} tasks from {1} were returned to be done",new Object[]{updated,count});
    }
    
}
